package demo.practice.leetcode;

import java.util.HashSet;

public class Ms0101 {
    //https://leetcode-cn.com/problems/is-unique-lcci/
    //面试题 01.01. 判定字符是否唯一
    public static void main(String[] args) {
//        Ms0101 ms0101 = new Ms0101();
//        boolean leetcode = ms0101.isUnique("leetcode");
//        System.out.println(leetcode);

        System.out.println(5 << 1);
        System.out.println(5 >> 1);
        int a=0b0000010;//2
        int b=0b0000011;//3
        System.out.println(a);

        a|=3;

        int seen = 0b0000000;
        seen |= b;
        System.out.println(seen);

        a ^= b;
        b ^= a;
        a ^= b;

        System.out.println(a);
        System.out.println(b);
    }





    public boolean isUnique(String astr) {
        for(int i=0;i<astr.length();i++){
           if(astr.substring(i+1).contains(String.valueOf( astr.charAt(i) )) )
               return false;
        }
        return true;
    }

    public boolean isUnique2(String astr) {
        return astr.chars().distinct().count() == astr.length();
    }

    public boolean isUnique3(String astr) {
        for(int i=0;i<astr.length();i++){
            if(astr.lastIndexOf(astr.charAt(i))!=i)
                return false;
        }
        return true;
    }


    public boolean isUnique4(String astr) {
        HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < astr.length(); i++) {
            set.add(astr.charAt(i));
        }
        return set.size() == astr.length();
    }
}
